﻿using System;
using System.Windows.Data;

namespace Moria.Silverlight.Converters
{
    public class CoordinateConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double param = 0;
            double val = 0;
            if (double.TryParse(parameter.ToString(), out param))
            {
                if (double.TryParse(value.ToString(), out val))
                value = (val * param);
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double param = 0;
            double val = 0;
            if (double.TryParse(parameter.ToString(), out param))
            {
                if (double.TryParse(value.ToString(), out val))
                    value = (val / param);
            }
            return value;
        }
    }
}
